package com.etoak.common.core.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * REST 接口返回值
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultVO<T> {

    /**
     * 执行成功的响应码
     */
    public static final int SUCCESS_CODE = 200;

    /**
     * 执行成功后的响应消息
     */
    public static final String SUCCESS_MESSAGE = "success";

    /**
     * 执行失败后的响应码
     */
    public static final int FAILED_CODE = 500;

    /**
     * 执行失败后的响应消息
     */
    public static final String FAILED_MESSAGE = "系统异常";

    private Integer code;

    private String message;

    private T data;

    /**
     * 添加、更新、删除接口使用
     */
    public static <T> ResultVO<T> success() {
        return success(null);
    }

    /**
     * 查询接口
     */
    public static <T> ResultVO<T> success(T data) {
        return new ResultVO<>(SUCCESS_CODE, SUCCESS_MESSAGE, data);
    }

    public static <T> ResultVO<T> failed() {
        return failed(FAILED_MESSAGE);
    }

    public static <T> ResultVO<T> failed(String message) {
        return failed(FAILED_CODE, message);
    }

    public static <T> ResultVO<T> failed(int code, String message) {
        return new ResultVO<>(code, message, null);
    }
}
